package com.niiwoo.civet.account.service.dubbo;

import com.alibaba.fastjson.JSON;
import com.niiwoo.civet.account.AccountServiceApplication;
import com.niiwoo.civet.account.dao.entity.*;
import com.niiwoo.civet.account.enums.OpenAccountMajorWay;
import com.niiwoo.civet.account.enums.OpenAccountWayEnum;
import com.niiwoo.civet.account.service.local.openAccount2.dto.*;
import com.niiwoo.civet.account.service.local.openAccount2.service.OpenAccountServices;
import com.niiwoo.civet.base.constant.OrgConstant;
import com.niiwoo.tripod.lanmao.component.*;
import com.niiwoo.tripod.lanmao.enums.*;
import com.niiwoo.tripod.lanmao.response.LanMaoGatewayDTO;
import com.niiwoo.tripod.service.component.SnowflakeIdWorker;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 开户测试
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AccountServiceApplication.class)
public class AccountRegisterDubboServiceImplTest2 {

    @Autowired
    OpenAccountServices openAccountServices;

    @Autowired
    SnowflakeIdWorker snowflakeIdWorker;

    @Autowired
    LanMaoSequence sequence;

    @Test
    public void sequence() {
        System.out.println("s: " + sequence.getRequestNo());
    }

    @Test
    public void ids() {
        for (int i = 0; i < 50; i++) {
            System.out.println("id: " + snowflakeIdWorker.nextId());
        }
    }


    /********************* 开户状态查询 *****************************/

    @Test
    public void vetifyStatus() {
        OpenAccountMajorWay openAccountMajorWay = openAccountServices.verifyAndGetOpenAccountWay(OrgConstant.NIIWOO_ORG_ID, "70000000001", UserRoleEnum.BORROWERS);
        log.info("开户方式：{}", openAccountMajorWay);
    }

    /********************* 查询更新 *****************************/

    @Test
    public void queryOpenAccountUpdate() {
        QueryUpdateRequest request = new QueryUpdateRequest();
        request.setUserId("74ff5251-37d7-43e7-a3fe-1e30ff8b1a26");
        request.setRole(UserRoleEnum.BORROWERS.getValue());
        UpdateResponse update = openAccountServices.get(Void.class).update(request);
        log.info("查询更新结果：{}", JSON.toJSONString(update));
    }

    /********************* 个人绑卡 *****************************/

    @Test
    public void registerAccountCreate() {
        RegisterCreateRequest request = new RegisterCreateRequest();
        request.setUserId("70000000015");
        request.setIdCardNo("630102199211145259");
        request.setBankCardNo("6212860000281858");
        request.setBankCardMobileNo("13670028012");
        request.setName("云超2");
        request.setRole(UserRoleEnum.INVESTOR);
        request.setOpenAccountWay(OpenAccountWayEnum.PERSON_BIND_BANK_CARD_REGISTER);
        LanMaoGatewayDTO lanMaoGatewayDTO = openAccountServices.get(OpenAccountOrder.class).create(request);
        log.info("个人绑卡请求：{}", JSON.toJSONString(lanMaoGatewayDTO));
    }

    @Test
    public void registerAccountUpdate() {
        RegisterUpdateRequest request = new RegisterUpdateRequest();
        request.setIsBizSuccess(true);
        request.setRequestNo("172_21_0_210-8080-60000036302018030614152743");
        request.setAccessType(AuthorityTypeEnum.FULL_CHECKED);
        request.setAccountNo("53975637073035265");
        request.setGroupAccountNo("GA20180306141902138bdd");
        request.setAuditStatus(AuditStatusEnum.PASSED);
        request.setBankCode(BankCodeEnum.CMBC);
        request.setErrorCode("");
        request.setErrorMessage("");
        UpdateResponse update = openAccountServices.get(OpenAccountOrder.class).update(request);
        log.info("个人绑卡更新：{}", JSON.toJSONString(update));
    }

    /********************* 个人激活 *****************************/

    @Test
    public void activateAccountCreate() {
        CreateRequest request = new CreateRequest();
        request.setUserId("70000000025");
        request.setRole(UserRoleEnum.GUARANTEECORP);
        request.setOpenAccountWay(OpenAccountWayEnum.ENTERPRISE_ACTIVATE);
        LanMaoGatewayDTO lanMaoGatewayDTO = openAccountServices.get(ActivateAccountOrder.class).create(request);
        log.info("个人激活请求：{}", JSON.toJSONString(lanMaoGatewayDTO));
    }

    @Test
    public void activateAccountUpdate() {
        /**
         * 个人
         {
         "platformUserNo":"51766278196707330",
         "userRole":"INVESTOR",
         "realName":"贡冰",
         "idCardType":"PRC_ID",
         "idCardNo":"360727198103226579",
         "bankcardNo":"6212860000289856",
         "bankcode":"CMBC",
         "mobile":"13901341681",
         "accessType":"FULL_CHECKED",
         "auditStatus":"PASSED",
         "cardNoIsChange":"FALSE",
         "groupAccountNO":"GA20180306203323000c7d",
         "requestNo":"172_21_0_210-8080-600000363020180306203122131",
         "code":"0",
         "status":"SUCCESS"
         }
         */
        /**
         * 企业
         *
         * {
         "platformUserNo":"51766278200901635",
         "userRole":"GUARANTEECORP",
         "realName":"国隆达非融资性担保（深圳）有限公司",
         "idCardType":"PRC_ID",
         "idCardNo":"362203198708296849",
         "bankcardNo":"765368950629",
         "bankcode":"BKCH",
         "mobile":"18682006920",
         "accessType":"PART_CHECKED",
         "auditStatus":"AUDIT",
         "requestNo":"172_21_0_210-8080-60000036302018030711500520",
         "code":"0",
         "status":"SUCCESS"
         }
         */
        ActivateUpdateRequest request = new ActivateUpdateRequest();
        request.setAccessType(AuthorityTypeEnum.FULL_CHECKED);
        request.setBankCardMobileNo("13901341681");
        request.setBankCardNo("6212860000289856");
        request.setBankCode(BankCodeEnum.CMBC);
        request.setIsBizSuccess(true);
        request.setRequestNo("172_21_0_210-8080-600000363020180306203122131");
        request.setAccountNo("51766278196707330");
        request.setGroupAccountNo("GA20180306203323000c7d");
        request.setAuditStatus(AuditStatusEnum.PASSED);
        request.setName("贡冰");
        request.setIdCardNo("360727198103226579");
        request.setErrorCode("");
        request.setErrorMessage("");
        UpdateResponse update = openAccountServices.get(ActivateAccountOrder.class).update(request);
        log.info("个人激活更新：{}", JSON.toJSONString(update));
    }

    /********************* 集团账户关联并新建 *****************************/

    @Test
    public void groupAccountCreate() {
        CreateRequest request = new CreateRequest();
        request.setUserId("70000000015");
        request.setRole(UserRoleEnum.BORROWERS);
        request.setOpenAccountWay(OpenAccountWayEnum.GROUP_ACCOUNT_CORRELATE);
        LanMaoGatewayDTO lanMaoGatewayDTO = openAccountServices.get(GroupAccountCorrelateOrder.class).create(request);
        log.info("集团账户关联并新建请求：{}", JSON.toJSONString(lanMaoGatewayDTO));
    }
    @Test
    public void groupAccountUpdate() {
        UpdateRequest request = new UpdateRequest();
        request.setAccountNo("53978792179277825");
        request.setRequestNo("172_21_0_210-8080-60000036302018030614275945");
        request.setIsBizSuccess(true);
        request.setAuditStatus(AuditStatusEnum.PASSED);
        request.setErrorCode("");
        request.setErrorMessage("");
        UpdateResponse update = openAccountServices.get(GroupAccountCorrelateOrder.class).update(request);
        log.info("集团账户关联并新建更新：{}", JSON.toJSONString(update));
    }

    /********************* 集团账户关联并激活 *****************************/

    @Test
    public void groupAccountCreate2() {
        CreateRequest request = new CreateRequest();
        request.setUserId("70000000002");
        request.setRole(UserRoleEnum.BORROWERS);
        request.setOpenAccountWay(OpenAccountWayEnum.GROUP_ACCOUNT_CORRELATE);
        LanMaoGatewayDTO lanMaoGatewayDTO = openAccountServices.get(GroupAccountCorrelateOrder.class).create(request);
        log.info("集团账户关联并新建请求：{}", JSON.toJSONString(lanMaoGatewayDTO));
    }

    @Test
    public void groupAccountUpdate2() {
        /**
         * {"platformUserNo":"51766278196707328","type":"ACTIVE_AUTH","groupAccountNo":"GA20180306192855950809","requestNo":"172_21_0_210-8080-600000363020180306194311130","code":"0","status":"SUCCESS"}
         */
        UpdateRequest request = new UpdateRequest();
        request.setAccountNo("51766278196707328");
        request.setRequestNo("172_21_0_210-8080-600000363020180306194311130");
        request.setIsBizSuccess(true);
        request.setAuditStatus(AuditStatusEnum.PASSED);
        request.setErrorCode("");
        request.setErrorMessage("");
        UpdateResponse update = openAccountServices.get(GroupAccountCorrelateOrder.class).update(request);
        log.info("集团账户关联并新建更新：{}", JSON.toJSONString(update));
    }


    /********************* 企业绑卡 *****************************/
    @Test
    public void entepriseAccountCreate() {

    }


    /********************* 企业激活更新 *****************************/
    @Test
    public void enterpriseAccountUpdate() {
        EnterpriseRegisterUpdateRequest mockEnterpriseRegisterUpdateRequest = new EnterpriseRegisterUpdateRequest();
        mockEnterpriseRegisterUpdateRequest.setIsBizSuccess(true);
        mockEnterpriseRegisterUpdateRequest.setBankCardNo("765368952629");
        //mockEnterpriseRegisterUpdateRequest.setBankCode(BankCodeEnum.BKCH.getCode());
        mockEnterpriseRegisterUpdateRequest.setAccountNo("54340426596884489");
        mockEnterpriseRegisterUpdateRequest.setAuditStatus(AuditStatusEnum.PASSED);
        mockEnterpriseRegisterUpdateRequest.setRequestNo("172_21_0_210-8080-60000036302018031919165821");
        mockEnterpriseRegisterUpdateRequest.setErrorMessage("");
        mockEnterpriseRegisterUpdateRequest.setErrorCode("");
        UpdateResponse update = openAccountServices.get(EnterpriseRegisterOrder.class).update(mockEnterpriseRegisterUpdateRequest);
        log.info("企业更新：{}", JSON.toJSONString(update));

    }

}